﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.COM;

namespace MINERP.DAL.CommonDAL
{
    public class Shop_BillDAL:DALBase
    {
        /// <summary>
        /// 得到此商户下一个帐单的帐单号
        /// </summary>
        /// <param name="shopId"></param>
        /// <returns></returns>
        public static int GetNextBillOrder(int shopId)
        {

            //int currentNum = Convert.ToInt32( DataEntites.SHOP_Bill.Where(s => s.CreateTime.Month == DateTime.Now.Month).Max(sb => sb.BillOrderCode));
            List<SHOP_Bill> listShopBill = DataEntites.SHOP_Bill.Where(s => s.CreateTime.Month == DateTime.Now.Month && s.Shop.ShopId == shopId).ToList();
          if (listShopBill.Count<=0)
          {
              return 1;
          }
          else
          {
              return listShopBill.Max(sb => sb.BillOrderCode) + 1;
          }
           //return  DataEntites.SHOP_Bill.Where(s=>s.CreateTime.Month==DateTime.Now.Month).Max(sb => sb.BillOrderCode) + 1;
        }

        public static void AddNewObject(SHOP_Bill sb)
        {
            DataEntites.AddToSHOP_Bill(sb);
        }

        /// <summary>
        /// 得到小于某个时间（主要是天数即几月几号与具体的时间无关）的某种状态的所有定单
        /// </summary>
        /// <param name="shopid"></param>
        /// <param name="status"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public static List<SHOP_Bill> GetBillByShopIdAndStatus(int shopid, ShopBillStatus status,DateTime time)
        {
            int INtstatus = (int)status;
            DateTime Date = new DateTime(time.Year, time.Month, 1);
         //DateTime  DateT= new DateTime(Date.Year,Date.Month,1)
            //return DataEntites.SHOP_Bill.Where(sb => sb.Shop.ShopId == shopid && sb.Status == INtstatus && sb.CreateTime < Date).ToList();

            return DataEntites.SHOP_Bill.Where(sb => sb.Shop.ShopId == shopid && sb.Status == INtstatus && Date>sb.CreateTime).ToList();
        }
    }
}
